package com.example.taximeter.controller;


import com.example.taximeter.bean.*;
import com.example.taximeter.service.PriceService;
import com.example.taximeter.service.TaximeterTypeService;
import com.example.taximeter.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 计价器型号
 */
@RestController
@RequestMapping(value = "/taximetertype")
public class TaximeterTypeController {


    private TaximeterTypeService taximeterTypeService;
    private UserService userService;
//    private final static Logger logger = LoggerFactory.getLogger(ParamFileController.class);


    @Autowired
    public TaximeterTypeController(TaximeterTypeService taximeterTypeService,UserService userService){
        this.taximeterTypeService = taximeterTypeService;
        this.userService = userService;
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<TaximeterType> findTaximeterTypeList(){
        return taximeterTypeService.findTaximeterTypeList();
    }

    //查看计价器型号列表
    @RequestMapping(value = "/all",method = RequestMethod.POST)
    public ReturnInfo findPriceAll(@RequestParam(value = "pageNum", defaultValue = "0") String pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "0") String pageSize,
                                   @RequestBody TaximeterTypeView taximeterTypeView) {
        //添加日志
        userService.addUserLog(7,taximeterTypeView.toString());
        return taximeterTypeService.findTaximeterTypeAll(Integer.valueOf(pageNum), Integer.valueOf(pageSize), taximeterTypeView);
    }

    //新增计价器型号
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ReturnInfo addPrice(@RequestBody  @Validated(GroupCreate.class) TaximeterType taximeterType){
        String mes = taximeterTypeService.addTaximeterType(taximeterType);
        if(mes.equals("成功")){
//            logger.info("新增计价器型号"+taximeterType.toString());
            //添加日志
            userService.addUserLog(4,taximeterType.toString());
        }
        return ReturnInfo.info1(mes);
    }

    //修改计价器型号
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ReturnInfo updatePrice(@RequestBody  @Validated(GroupUpdate.class) TaximeterTypeView taximeterTypeView){
        String mes = taximeterTypeService.updateTaximeterType(taximeterTypeView);
        if(mes.equals("成功")){
//            logger.info("修改计价器型号"+taximeterTypeView.toString());
            //添加日志
            userService.addUserLog(5,taximeterTypeView.toString());
        }
        return ReturnInfo.info1(mes);
    }

    //删除计价器型号
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    public ReturnInfo deletePrice(@PathVariable Integer id){
        String mes = taximeterTypeService.deleteTaximeterType(id);
        if(mes.equals("成功")){
//            logger.info("删除计价器型号"+String.valueOf(id));
            //添加日志
            userService.addUserLog(6,String.valueOf(id));
        }
        return ReturnInfo.info1(mes);
    }

    //查看计价器型号(计价器厂商)
    @RequestMapping(value = "/factjjqtype",method = RequestMethod.POST)
    public List<TaximeterType> findJjqtypeByFactname(@RequestParam String factname) {
            return taximeterTypeService.findJjqtypeByFactname(factname);

    }

    //查看计价器型号(计价器厂商id)
    @RequestMapping(value = "/factidjjqtype",method = RequestMethod.POST)
    public List<TaximeterType> findJjqtypeByFactid(@RequestParam Integer factid) {
        return taximeterTypeService.findJjqtypeByFactid(factid);

    }
}
